import requests

# 登录获取token
login_url = "http://localhost:10003/user-service/auth/login"
login_data = {
    "username": "admin",
    "password": "123456"
}

response = requests.post(login_url, json=login_data)
print("Login response:", response.text)

if response.status_code == 200:
    token = response.json()["data"]
    print("Token:", token)
    
    # 上传文件
    upload_url = "http://localhost:10003/document-service/literature/upload"
    headers = {
        "Authorization": f"Bearer {token}"
    }
    
    with open("test.txt", "rb") as f:
        files = {"file": f}
        data = {
            "title": "Test Document",
            "authors": "Test Author"
        }
        
        upload_response = requests.post(upload_url, headers=headers, files=files, data=data)
        print("Upload response:", upload_response.text)
else:
    print("Login failed")